"""
lambda的应用  重点

1 带判断的lambda
"""

fn1 = lambda a,b : a if a-b else b
print(fn1(10,20))

# 列表数据按字典key的值进行排序
students = [
    {'name':'Tom','age':20,'gender':'男'},
    {'name':'Sarry','age':21,'gender':'女'},
    {'name':'Alin','age':8,'gender':'女'}
]

# 按name值进行升序排序
students.sort(key=lambda x :x['name']) # reverse=False 是升序
print(students)

# 按age值进行升序排序
students.sort(key=lambda x : x['age'],reverse=True) # reverse=False 是升序
print(students)
print(students[1]['name'])